%% just look at raw as() output
clear
clc
asRead = load('asReadOutput.mat');

f = figure(10);
clf(f);
n = size(asRead.d, 2);
m = size(asRead.d, 1);

cMap = lines(n);
for ii = 1:n
    ax = subplot(n, 1, ii, ...
        'Parent', f);
    
    line(1:m, asRead.d(:,ii), ...
        'Parent', ax, ...
        'Color', cMap(ii,:))
    
    ylabel(ax, sprintf('column %d', ii))
end

%% load some of Matt's test data
clear
clc

% MARINO_BLINKING.mat
% MARINO_hits_the_corners.mat
% MARINO_center_to_upperRight.mat
% rolloverDataset.mat
topsDataLog.readDataFile('rolloverDataset.mat');


theLog = topsDataLog.theDataLog;
allData = theLog{'dotsQueryableEyeASL.allData'};
data = allData{1};
frameHints = theLog{'dotsQueryableEyeASL.frameTimestamps'};
hints = frameHints{1};

%% load different data
clear
clc
% mattGoesOneToNine.mat
load('mattGoesOneToNine')
data = calPointData(1).item;
hints = calPointData(2).item;

%% look at the scaled x y and diameter
f = figure(11);
clf(f);
n = 3;
cMap = lines(n);
for ii = 1:n
    ax = subplot(n, 1, ii, ...
        'Parent', f);
    
    dimSelector = data(:,1) == ii;
    xAxis = data(dimSelector,3);
    
    line(xAxis, data(dimSelector,2), ...
        'Parent', ax, ...
        'Color', cMap(ii,:))
    
    line(xAxis, data(dimSelector,2), ...
        'Parent', ax, ...
        'Color', cMap(ii,:))
end

%% look at the GetSecs and frame number timestamps

dimSelector = data(:,1) == 1;
allTimes = data(dimSelector,3);
m = length(allTimes);
zeroTimes = allTimes - allTimes(1);
diffTimes = [diff(allTimes); 0];

locals = zeros(1, size(hints, 1));
for ii = 1:length(locals)
    time = hints(ii,2);
    locals(ii) = find(allTimes==time, 1, 'first');
end

f = figure(12);
clf(f);
ax = subplot(2,1,1, ...
    'Parent', f);
line(1:m, zeroTimes, ...
    'LineStyle', 'none', ...
    'Marker', '.')
line(locals, zeroTimes(locals), ...
    'LineStyle', 'none', ...
    'Marker', '.', ...
    'Color', 'r');
ylabel('running time')
legend('interpolated', 'local time', 'Location', 'NorthWest')

ax = subplot(2,1,2, ...
    'Parent', f);
line(1:m, diffTimes, ...
    'LineStyle', 'none', ...
    'Marker', '.')

line(locals, diffTimes(locals), ...
    'LineStyle', 'none', ...
    'Marker', '.', ...
    'Color', 'r');
ylabel('sample interval')

%% reconstruct the frame numbers
sampleFrequency = 120;
dimSelector = data(:,1) == 1;
frameTimes = data(dimSelector,3);
frameNumbers = dotsQueryableEyeASL.reconstructFrameNumbers( ...
    frameTimes, hints, sampleFrequency);
nFrames = numel(frameNumbers);

f = figure(13);
clf(f);
ax = subplot(2,1,1, ...
    'Parent', f);
line(1:nFrames, frameNumbers, ...
    'LineStyle', 'none', ...
    'Marker', '.')
ylabel('frame number')

ax = subplot(2,1,2, ...
    'Parent', f);
line(2:nFrames, diff(frameNumbers), ...
    'LineStyle', 'none', ...
    'Marker', '.')
ylabel('frame skips?')
